//
//  UphotOrderVC.m
//  WuyouTang
//
//  Created by ybRRR on 2023/7/13.
//  Copyright © 2023 cat. All rights reserved.
//

#import "UphotOrderVC.h"
#import <TYTabPagerBar.h>
#import <TYPagerController.h>
#import "HotVideoDetailVC.h"
#import "LiveOrderDetailVC.h"

@interface UphotOrderVC ()<TYTabPagerBarDelegate,TYTabPagerBarDataSource,TYPagerControllerDelegate,TYPagerControllerDataSource>
@property(nonatomic,strong)TYTabPagerBar *tabBar;
@property(nonatomic,strong)TYPagerController *pagerController;
@property(nonatomic,strong)NSArray *dataArray;

@end

@implementation UphotOrderVC

- (void)viewDidLoad {
    self.naviView.hidden = YES;
    CGFloat cellSpace = 40;

    _dataArray = @[YZMsg(@"视频明细"),YZMsg(@"直播明细")];
    [super viewDidLoad];
    TYTabPagerBar *tabBar = [[TYTabPagerBar alloc]init];
    tabBar.dataSource = self;
    tabBar.delegate = self;
    tabBar.layout.barStyle = TYPagerBarStyleProgressView;
    tabBar.layout.selectedTextColor = UIColor.whiteColor;
    tabBar.layout.normalTextColor = UIColor.whiteColor;
    tabBar.layout.selectedTextFont = [UIFont boldSystemFontOfSize:17];
    tabBar.layout.normalTextFont = [UIFont boldSystemFontOfSize:14];
    tabBar.layout.progressColor = UIColor.clearColor;
    tabBar.layout.progressHeight = 4;
    tabBar.layout.progressRadius = 2;
    tabBar.layout.progressHorEdging = 10;
    tabBar.layout.progressVerEdging = 5;
    tabBar.layout.cellWidth = 0;
    tabBar.layout.cellSpacing = cellSpace;
    tabBar.layout.adjustContentCellsCenter = YES;
    tabBar.backgroundColor = UIColor.clearColor;
    tabBar.frame = CGRectMake(60, 24+statusbarHeight, _window_width-120, 40);
    [tabBar registerClass:[TYTabPagerBarCell class] forCellWithReuseIdentifier:[TYTabPagerBarCell cellIdentifier]];
    [self.naviView addSubview:tabBar];
    _tabBar = tabBar;

    
    TYPagerController *pagerController = [[TYPagerController alloc] init];
    pagerController.dataSource = self;
    pagerController.delegate = self;
    pagerController.layout.adjustScrollViewInset = NO;
    pagerController.layout.scrollView.backgroundColor = Normal_Color;
    pagerController.view.frame = CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight);
    [self addChildViewController:pagerController];
    [self.view addSubview:pagerController.view];
    _pagerController = pagerController;
    [_tabBar reloadData];
    [_pagerController updateData];

}

#pragma mark - TYTabPagerBarDataSource
- (NSInteger)numberOfItemsInPagerTabBar {
    return _dataArray.count;
}
- (UICollectionViewCell<TYTabPagerBarCellProtocol> *)pagerTabBar:(TYTabPagerBar *)pagerTabBar cellForItemAtIndex:(NSInteger)index {
    UICollectionViewCell<TYTabPagerBarCellProtocol> *cell = [pagerTabBar dequeueReusableCellWithReuseIdentifier:[TYTabPagerBarCell cellIdentifier] forIndex:index];
    cell.titleLabel.text = _dataArray[index];
    return cell;
}

#pragma mark - TYTabPagerBarDelegate
- (CGFloat)pagerTabBar:(TYTabPagerBar *)pagerTabBar widthForItemAtIndex:(NSInteger)index {
    NSString *title = _dataArray[index];
    return [pagerTabBar cellWidthForTitle:title];
}

- (void)pagerTabBar:(TYTabPagerBar *)pagerTabBar didSelectItemAtIndex:(NSInteger)index {
    [_pagerController scrollToControllerAtIndex:index animate:YES];
}

#pragma mark - TYPagerControllerDataSource
- (NSInteger)numberOfControllersInPagerController {
    return _dataArray.count;
}
- (UIViewController *)pagerController:(TYPagerController *)pagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
    if (index == 0) {
        HotVideoDetailVC  *videoDetail = [[HotVideoDetailVC alloc]init];
        return videoDetail;
    }else{
        // 收藏
        LiveOrderDetailVC *live = [[LiveOrderDetailVC alloc]init];
        return live;
    }
}
#pragma mark - TYPagerControllerDelegate
- (void)pagerController:(TYPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated {
    [_tabBar scrollToItemFromIndex:fromIndex toIndex:toIndex animate:animated];
}
-(void)pagerController:(TYPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress {
    [_tabBar scrollToItemFromIndex:fromIndex toIndex:toIndex progress:progress];
}
@end
